﻿//----------------------------------------------------------------------------------------------------
// The IGameState base class for game states
//----------------------------------------------------------------------------------------------------

package HG.GameStates
{
	import flash.events.*;
	
	import HG.GameService;
	import HG.Managers.GameRuleManager;
	import HG.Managers.PlayerManager;
	import HG.Managers.StateManager;
	import flash.utils.Timer;
	
	public class PostGameState extends IGameState
	{
		var m_gameRuleManager:GameRuleManager;
		var m_playerManager:PlayerManager;
		var m_stateManager:StateManager;
		
		//----------------------------------------------------------------------------------------------------
		public function PostGameState()
		{
			m_stateName = "PostGameState";
		}
		
		//----------------------------------------------------------------------------------------------------
		public override function Begin()
		{
			super.Begin();
			
			m_gameRuleManager = GameService.GetInstance().GetGameRuleManager();
			m_playerManager = GameService.GetInstance().GetPlayerManager();
			m_stateManager = GameService.GetInstance().GetStateManager();
			
			
			m_movie.Content.Button_Continue.addEventListener(MouseEvent.CLICK, Button_Continue);
			
			SetUpStats();
		}
		
		//----------------------------------------------------------------------------------------------------
		public override function End()
		{
			super.End();
			
			m_playerManager.FlushPlayers();
		}
		
		//----------------------------------------------------------------------------------------------------
		public override function OnTick(DetaTime:Number)
		{
			
		}
		
		//----------------------------------------------------------------------------------------------------
		// Button Callbacks
		//----------------------------------------------------------------------------------------------------
		private function Button_Continue(me:MouseEvent):void
		{
			m_stateManager.SwitchtoState(StateManager.STATE_PLAY);
		}
		
		//----------------------------------------------------------------------------------------------------
		// Internal functions
		//----------------------------------------------------------------------------------------------------
		private function SetUpStats()
		{
			var playerID:Number = m_playerManager.GetCurrentPlayerID();
			
			
			// Fate --------------------------------
			var fateText:String = "Unknown";
			switch(m_gameRuleManager.GetPlayerFate(playerID))
			{
				case GameRuleManager.FATE_VICTORY:
				{
					fateText = "Victory";
				}break;
				case GameRuleManager.FATE_DEFEAT:
				{
					fateText = "Defeat"
				}
			}
			m_movie.Content.TXT_Fate.text = fateText;
			
			// Documents --------------------------------
			var capedDocs:Number = m_gameRuleManager.GetPlayerDocs(playerID);
			var totalDocs:Number = m_gameRuleManager.GetTotalDocs();
			m_movie.Content.Documents.SetLabel("DOCUMENTS:");
			m_movie.Content.Documents.SetValue(capedDocs + "/" + totalDocs, 500);
			
			// Intrusion  --------------------------------
			var capedNodes:Number = m_gameRuleManager.GetPlayerCaps(playerID);
			var totalNodes:Number = m_gameRuleManager.GetTotalNodes();
			m_movie.Content.Intrusion.SetLabel("INTRUSION:");
			m_movie.Content.Intrusion.SetValue(capedNodes + "/" + totalNodes, 1000);
			
			// Sentries  --------------------------------
			var kills:Number = m_gameRuleManager.GetPlayerKills(playerID);
			var totalSentries:Number = m_gameRuleManager.GetTotalSentries();
			m_movie.Content.Sentries.SetLabel("SENTRIES:");
			m_movie.Content.Sentries.SetValue(kills + "/" + totalSentries, 1500);
			
			// Complete   --------------------------------
			var per:Number = Math.round(((capedDocs + capedNodes  + kills) / (totalDocs + totalNodes + totalSentries)) * 100);
			m_movie.Content.Complete.SetValue(per, 2000);
		}
		//----------------------------------------------------------------------------------------------------
	}

}